//
//  SGSpecificViewModel.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/15.
//  Copyright © 2016年 pcz. All rights reserved.
//

import UIKit

class SGSpecificViewModel: NSObject {
    var cellHeight : CGFloat?
    var labelHeight : CGFloat     = 0
    var imageViewHeight : CGFloat = 0
    var resourceModel : SGResourceModel?
    
    
    class func initWithResourceModel(resourceModel : SGResourceModel) -> SGSpecificViewModel{
        let specific = SGSpecificViewModel()
        specific.resourceModel = resourceModel
        let width = screenWidth - 2 * margin
        
        switch resourceModel.tp! {
        case .Text: // 文字
            if resourceModel.isSubTitle { // 标题
                specific.labelHeight = (resourceModel.txt! as NSString).boundingRectWithSize(CGSize(width: width, height: screenHeight), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName : UIFont.systemFontOfSize(14, weight: 6)], context: nil).size.height
            }else{
                specific.labelHeight = (resourceModel.txt! as NSString).boundingRectWithSize(CGSize(width: width, height: screenHeight), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName : UIFont.systemFontOfSize(14)], context: nil).size.height
            }
            specific.cellHeight = specific.labelHeight + 20
        default : // 图片
            specific.imageViewHeight = width / (resourceModel.width)! * (resourceModel.height)!
            specific.cellHeight = specific.imageViewHeight + 20
        }
        return specific
    }

}
